package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.RenewContractNotice;
import com.amsp.oa.oademo.service.RenewContractNoticeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "续订劳动合同通知书管理")
@RestController
@RequestMapping("/api/renewContractNotice")
public class RenewContractNoticeController {

    @Autowired
    private RenewContractNoticeService renewContractNoticeService;

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public IPage<RenewContractNotice> getPage(
            @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页记录数") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("员工姓名") @RequestParam(required = false) String applicant) {
        Page<RenewContractNotice> page = new Page<>(current, size);
        return renewContractNoticeService.getPage(page, applicant);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public RenewContractNotice getById(@PathVariable Long id) {
        return renewContractNoticeService.getById(id);
    }

    @ApiOperation("保存或更新")
    @PostMapping("/save")
    public boolean save(@RequestBody List<RenewContractNotice> notices) {
        return renewContractNoticeService.saveOrUpdateBatchTran(notices);
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return renewContractNoticeService.removeById(id);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public boolean batchDelete(@RequestBody List<Long> ids) {
        return renewContractNoticeService.removeByIds(ids);
    }
}